<!-- 22116651 -->
<!-- appsecret：b6oho8mT      -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" name="city" id="city"><button>获取天气</button>
    <textarea name="" id="tianqi" cols="30" rows="10"></textarea>
    <script>
        const btn = document.querySelector('button');
        const textArea = document.querySelector('#tianqi');

        btn.onclick = function(){
            let city = document.querySelector('#city').value;
            let url = `https://v0.yiketianqi.com/api?unescape=1&version=v91&appid=22116651&appsecret=b6oho8mT&ext=&cityid=&city=${city}`
            const xhr = new XMLHttpRequest();
            xhr.open('get',url);
            xhr.responseType = 'json';
            xhr.send();
            xhr.onreadystatechange = function(){
                if(xhr.readyState ===4){
                    if(xhr.status >=200 && xhr.status < 300){
                        console.log(xhr.response,typeof xhr.response);
                        let cityData = xhr.response;
                        textArea.innerHTML = `城市： ${cityData.city} \r\n
                               时间： ${cityData.data[0].date} \r\n
                               空气质量：${cityData.data[0].air} \r\n
                        `;
                    }
                }
            }
        }
    </script>
</body>
</html>